﻿using System;
using System.IO;

class ScoreTable
{
    static void PrintScoreTable(string[,] score)
    {
        Console.ForegroundColor = ConsoleColor.White;
        for (int row = 0; row < score.GetLength(0); row++)
        {
            Console.SetCursorPosition(50, row);
            for (int col = 0; col < score.GetLength(1); col++)
            {                
                bool isBackgroundColorChanged = false;
                if (col % 2 != 0)
                {
                    Console.BackgroundColor = ConsoleColor.DarkGray;
                    isBackgroundColorChanged = true;
                }

                if (row % 2 != 0)
                {
                    Console.Write(new string('_', 18));
                }
                else
                {
                    if (score[row, col] != null)
                    {
                        Console.Write("{0}", score[row, col].PadLeft(18));
                    }
                    else
                    {
                        Console.Write(string.Empty.PadLeft(18));
                    }
                }
        
                if (isBackgroundColorChanged)
                {
                    Console.BackgroundColor = ConsoleColor.Black;
                }
            }
            Console.WriteLine();
        }
    }

    static void ResultTable(string currentThrowing, int numOfPlayers)
    {
        int namesLength = numOfPlayers * 2;
        string[,] table = new string[35, numOfPlayers + 1];

        for (int col = 1; col < numOfPlayers +1; col++)
        {
            Console.Write("Enter the name of player {0}: ", col);
            table[0, col] = Console.ReadLine();
            table[0, col] += " ".PadLeft((18 - table[0, col].Length) / 2);
            namesLength += table[0, col].Length;
        }
        Console.Clear();

        try
        {
            using (StreamReader sr = new StreamReader("ThrowingCombinations.txt"))
            {
                int row = 0;
                for (string line; (line = sr.ReadLine()) != null; row += 2)
                {
                        table[row, 0] = line + " ".PadLeft((18 - line.Length) / 2);
                }
            }
        }
        catch (FileNotFoundException ex)
        {
            Console.WriteLine("The file could not be read:");
            Console.WriteLine(ex.Message);
        }
        catch (UnauthorizedAccessException ex)
        {
            Console.WriteLine("The file could not be read:");
            Console.WriteLine(ex.Message);
        }

        PrintScoreTable(table);
    }

    static void Main()
    {
        Console.Write("Еnter the number of players: ");
        int numOfPlayers = int.Parse(Console.ReadLine());
        string currentThrowing = "56132";
        Console.BufferHeight = Console.WindowHeight = 40;
        Console.BufferWidth = Console.WindowWidth = 50 + (numOfPlayers + 1) * 18;
        
        ResultTable(currentThrowing, numOfPlayers);
    }
}